package visiopuce.ui.tree;

import java.util.List;

import org.eclipse.swt.graphics.Image;

import visiopuce.objets.Analyse;
import visiopuce.objets.Puce;
import visiopuce.objets.Resultat;
import visiopuce.service.PuceService;
import visiopuce.service.PuceServiceImpl;
import visiopuce.service.ResultatService;
import visiopuce.service.ResultatServiceImpl;

public class AnalyseNode extends TreeNode {

	private Analyse analyse;
	
	
	public AnalyseNode(Analyse analyse) {
		this(null, analyse);
	}

	public AnalyseNode(ITreeNode parent, Analyse analyse) {
		super(parent);
		this.analyse = analyse;
	}
	
	
	public String getName() {
		// TODO Auto-generated method stub
		return analyse.getTypeAnalyse().getLibelle()+" n°"+analyse.getIdAnalyse();
	}

	public Image getImage() {
//		return new Image(new Display(),"icons/array.jpg"); 
		return null;
	}
	
//	@Override
//	protected void createChildren(List children) {
////				AlterationService alterationService = AlterationServiceImpl
////				.getInstance();
////		List<Alteration> alterations = alterationService.findAllByidPuce(puce.getIdPuce());
////		for (Alteration alteration : alterations) {
////				children.add(new AlterationNode(this, alteration));
////		}
//	}
	
	@Override
	protected void createChildren(List children) {
		ResultatService renduService = ResultatServiceImpl
				.getInstance();
		List<Resultat> rendus = renduService.findAllByidAnalyse(analyse.getIdAnalyse());
		for (Resultat rendu : rendus) {
			children.add(new ResultatNode(this, rendu));
		}	
		PuceService puceService = PuceServiceImpl.getInstance();
		List<Puce> puces = puceService.findAllByidAnalyse(analyse.getIdAnalyse());
		for (Puce puce : puces) {
			children.add(new PuceNode(this, puce));
		}
	}
	

	public Analyse getAnalyse() {
		return analyse;
	}
}